<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>图片懒加载</title>
  <style>
    * {
      margin: 0;
    }
    .wrap {
      margin: 100px auto;
      width: 1000px;
    }
    .img-list {
      width: 700px;
    }
    .img-item {
      float: left;
      margin-bottom: 50px;
      list-style: none
    }
    .img-item:nth-child(even) {
      margin-left: 50px;
    }
    .img-item .img-wrap {
      width: 300px;
      height: 200px;
    }
    .img-item .img-wrap .list-img {
      width: 100%;
      height: 100%;
    }

  </style>
</head>
<body>
  <div class="wrap">
    <ul class="img-list">
      <!-- <li class="img-item">
        <div class="img-wrap">
          <img class="list-img" src="img/1.jpg" alt="" />
        </div>
        <div class="img-tt">
          <h1>图片1</h1>
        </div>
      </li> -->
    </ul>
  </div>
  <!-- 数据 -->
  <div id="img_data" style="display: none;">
    [
      {"img": "img/1.jpg", "name": "图片1"},
      {"img": "img/2.jpg", "name": "图片2"},
      {"img": "img/3.jpg", "name": "图片3"},
      {"img": "img/4.jpg", "name": "图片4"},
      {"img": "img/5.jpg", "name": "图片5"},
      {"img": "img/6.jpg", "name": "图片6"},
      {"img": "img/7.jpg", "name": "图片7"},
      {"img": "img/8.jpg", "name": "图片8"},
      {"img": "img/9.jpg", "name": "图片9"},
      {"img": "img/10.jpg", "name": "图片10"},
      {"img": "img/11.jpg", "name": "图片11"},
      {"img": "img/12.jpg", "name": "图片12"},
      {"img": "img/13.jpg", "name": "图片13"},
      {"img": "img/14.jpg", "name": "图片14"},
      {"img": "img/15.jpg", "name": "图片15"},
      {"img": "img/16.jpg", "name": "图片16"}
    ]
  </div>
  <!-- 模板 -->
  <script type="text/html" id="img_Tpl">
    <li class="img-item">
      <div class="img-wrap">
        <img class="list-img" src="img/d.jpg" data-src="{{img}}" alt="{{name}}" />
      </div>
      <div class="img-tt">
        <h1>{{name}}</h1>
      </div>
    </li>
  </script>

  <script src="./utils.js"></script>
  <script src="./index.js"></script>
</body>
</html>